package com.zqw.service.impl;

import com.zqw.info.OrderInfo;
import com.zqw.mapper.OrderMapper;
import com.zqw.pojo.*;
import com.zqw.service.OrderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;

    /**
     * 根据id查询订单
     * @param oid
     * @return
     */
    public OrderPojo queryOrder(String oid){
        return orderMapper.queryOrder(oid);
    }

    /**
     * 查询订单
     * @param orderInfo
     * @return
     */
    public List<OrderPojo> queryOrderss(OrderInfo orderInfo){
        return orderMapper.queryOrderss(orderInfo);
    }

    /**
     * 修改商品
     * @param orderInfo
     * @return
     */
    public boolean updOrder(OrderInfo orderInfo){
        return orderMapper.updOrder(orderInfo);
    }

    /**
     * 删除商品
     * @param oids
     * @return
     */
    public boolean delOrder(String[] oids){
        return orderMapper.delOrder(oids);
    }

    /**
     * 修改订单详情
     * @return
     */
    public boolean updOrderDetail(OrderDetailsPojo orderDetailsPojo){
        float v = (orderDetailsPojo.getOdprice() - orderDetailsPojo.getOldprice()) * orderDetailsPojo.getOdnumber();
        boolean b = orderMapper.updOrderDetail(orderDetailsPojo);
        if(!b){
            return false;
        }
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOcountPrice(v);
        orderInfo.setOid(orderDetailsPojo.getOid());
        boolean b1 = orderMapper.updOrderTwo(orderInfo);
        if(!b){
            return false;
        }
        return true;
    }

}
